﻿using System;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using IBS.Math;
using IBS.Model;

namespace BankApp.Models
{

    public class ChangePasswordModel
    {
        [Required]
        [Display(Name = "Current password")]
        [DataType(DataType.Password)]
        public string OldPassword { get; set; }

        [Required]
        [Display(Name = "New password")]
        [StringLength(100, ErrorMessage = "The {0} must be {2}-{1} characters long.", MinimumLength = 6)]
        [DataType(DataType.Password)]
        public string NewPassword { get; set; }

        [DataType(DataType.Password)]
        [Display(Name = "Confirm new password")]
        [Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
        public string ConfirmPassword { get; set; }
    }

    public class LogOnModel
    {
        [Required]
        [Display(Name = "User name")]
        [StringLength(50, ErrorMessage = "The {0} must be at most {1} characters long.")]
        [RegularExpression(@"[a-zA-Z]\w+", ErrorMessage = "{0} should contain letters or digits only. The first symbol has to be letter.")]
        public string UserName { get; set; }

        [Required]
        [Display(Name = "Password")]
        [StringLength(100, ErrorMessage = "The {0} must be {2}-{1} characters long.", MinimumLength = 6)]
        [DataType(DataType.Password)]
        public string Password { get; set; }

        [Display(Name = "Remember me?")]
        public bool RememberMe { get; set; }
    }

    public class RegisterModel
    {
        [Required]
        [Display(Name = "User name")]
        [StringLength(50, ErrorMessage = "The {0} must be at most {1} characters long.")]
        [RegularExpression(@"[a-zA-Z]\w+", ErrorMessage = "{0} should contain letters or digits only. The first symbol has to be letter.")]
        public string UserName { get; set; }

        [Required]
        [DataType(DataType.EmailAddress)]
        [Display(Name = "Email address")]
        [RegularExpression(@"\w+@[a-zA-Z0-9\-]+\.([a-zA-Z]{2,4}|[0-9]{1,3})", ErrorMessage = "Invalid Email format")]
        public string Email { get; set; }

        [Required]
        [StringLength(100, ErrorMessage = "The {0} must be {2}-{1} characters long.", MinimumLength = 6)]
        [DataType(DataType.Password)]
        [Display(Name = "Password")]
        public string Password { get; set; }

        [DataType(DataType.Password)]
        [Display(Name = "Confirm password")]
        [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
        public string ConfirmPassword { get; set; }

    }

    public class RegisterUserModel:RegisterModel
    {
        [Required]
        [Display(Name = "Code Card")]
        public int CodeCardNumber { get; set; }

        [Display(Name = "Request Number")]
        public int RequestNumber { get; set; }
    }

    public class CardModel
    {
        [HiddenInput]
        public int ClientId { get; set; }

        [Display(Name = "Card Type")]
        public CardType CardType { get; set; }

        [Display(Name = "Start Amount")]
        [Range(0.0, 100000000, ErrorMessage = "Incorrect amount")]
        public decimal StartAmount { get; set; }
    }


    public class CreditCheckModel
    {
        public Forecasting.Age? Age { get; set; }

        public Forecasting.Assets? Assets { get; set; }

        public Forecasting.DebtRatio? IncomeToDebtsRatio { get; set; }

        public Forecasting.Income? Income { get; set; }

        public Forecasting.PaymentHistory? PaymentHistory { get; set; }

        public Forecasting.Reliability? Reliability { get; set; }

        public Forecasting.FutureIncome? FutureIncome { get; set; }

        public double? Worthiness { get; set; }

        public string WorthinessDescription
        {
            get { return Worthiness == null ? null : Worthiness.Value.ToString("0.00") + "%"; }
        }
    }


    public enum CalcType
    {
        PV,
        FV,
        Rate,
        Payment,
        Period,
    }

    public class CalcModel
    {
        [Display(Name = "Present Value")]
        [DisplayFormat(DataFormatString = "{0:c}")]
        public double PV { get; set; }

        [Display(Name = "Future Value")]
        [DisplayFormat(DataFormatString = "{0:c}")]
        public double FV { get; set; }

        [Range(0, 2)]
        public double Rate { get; set; }
 
        public double Payment { get; set; }

        [Display(Name = "Continuous Compounding")]
        public bool ContCompounding { get; set; }

        [Display(Name = "Number of Periods")]
        [Range(0, 300)]
        public double Period { get; set; }

        [Display(Name = "Compounding Frequency")] 
        public TVM.Frequency Frequency { get; set; }

        public CalcType CalcType { get; set; }
        
        public double? Solution { get; set; }
    }


    public class ExchangeRate
    {
        [Required]
        public string Currency { get; set; }

        [Required]
        [DisplayFormat(DataFormatString = "MM/dd/yyyy")]
        public DateTime Date { get; set; }

        [Required]
        [DataType(DataType.Currency)]
        [Range(0.00001, 20000)]
        public decimal Ask { get; set; }

        [Required]
        [DataType(DataType.Currency)]
        [Range(0.00001, 20000)]
        public decimal Bid { get; set; }
    }

    public class CurrentRate
    {
        public string Currency { get; set; }
        public decimal NBRB { get; set; }
        public decimal Yahoo { get; set; }
        public decimal? ECB { get; set; }
        public decimal? FED { get; set; }        
        public decimal? Google { get; set; }
    }

    public enum DepositOrWithdraw
    {
        Deposit,
        Withdraw,
    }

    public class ExternalOperationModel
    {
        public int ClientId { get; set; }

        public string CardNumber { get; set; }

        public int TransferId { get; set; }

        public DepositOrWithdraw Type { get; set; }

        [Required]
        [Range(0.1, 100000000, ErrorMessage = "Incorrect amount")]
        public decimal Amount { get; set; }

        public string Currency { get; set; }
    }
}
